package com.zhugang.week05;

import java.util.HashSet;
import java.util.Set;

/**
 * @program algorithms
 * @description: findRepeatNumber
 * @author: chanzhugang
 * @create: 2022/07/08 16:27
 */
public class FindRepeatNumber {

    /**
     * 剑指offer 03 数组中重复的数字
     *
     * @param nums
     * @return
     */
    public int findRepeatNumber(int[] nums) {
        // 遍历数组，放入哈希表
        Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            if (set.contains(num)) {
                return num;
            }
            set.add(num);
        }
        return -1;
    }
}